package com.hello.sky.controller.admin;

import com.hello.sky.model.dto.CategoryDTO;
import com.hello.sky.model.entity.Category;
import com.hello.sky.model.dto.PageParamDto;
import com.hello.sky.model.entity.Dish;
import com.hello.sky.model.vo.DishVO;
import com.hello.sky.result.PageResult;
import com.hello.sky.result.Result;
import com.hello.sky.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜品及套餐分类 前端控制器
 * </p>
 *
 * @author D
 */
@Slf4j
@Tag(name = "分类")
@RestController
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryService  categoryService;

    @Operation(summary = "分类分页查询")
    @GetMapping("/page")
    public Result<PageResult> getPage(PageParamDto pageParamDto){
        PageResult page = categoryService.getPage(pageParamDto);
        return Result.success(page);
    }

    @Operation(summary = "更新类别")
    @PutMapping
    public Result update(@RequestBody Category category){
        categoryService.updateCategory(category);
        return Result.success();
    }

    @Operation(summary = "添加类别")
    @PostMapping
    public Result add(@RequestBody CategoryDTO dto){
        categoryService.addCategory(dto);
        return Result.success();
    }

    @Operation(summary = "启用、禁用分类")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable("status") Integer status, @RequestParam("id") Integer id){
        categoryService.updateStatus(status, id);
        return Result.success();
    }

    @Operation(summary = "根据id删除分类")
    @DeleteMapping
    public Result del(@RequestParam("id") Integer id){
        categoryService.delCategoryById(id);
        System.out.println(id);
        return Result.success();
    }

    @Operation(summary = "根据类型查询分类")
    @GetMapping("/list")
    public Result<List<Category>> getListByType(@RequestParam("type") Integer type){
        List<Category> listByType = categoryService.getListByType(type);
        return Result.success(listByType);
    }

}
